<?php 
/**
 * Class ScribeLogWrapper
 * performming Scribe log
 *
 * @author haumv
 * @version $Id: ScribeLogWrapper.php 4479 2012-11-02 03:10:41Z haumv $
 */
class SGN_ScribeLogWrapper
{
    static $_self = array();
    /**
     * loggingString
     *
     * @var String
     */
    private $_loggingString = '';
    /**
     * instance
     *
     * @var String
     */
    private $_instance = '';
    /**
     *
     * @var SGN_Scribe
     */
    private $_Log = null;
    /**
     * Factory method to ensure singleton
     *
     * @return WallfeedLog
     */
    public static function factory($channel)
    {
        if(!isset(self::$_self[$channel])){
            self::$_self[$channel] = new SGN_ScribeLogWrapper($channel);
        }
        return self::$_self[$channel];
    }
    /**
     * Class Constructor
     *
     * perform some initial action
     * Scribe logging
     */
    function __construct($channel)
    {
        //@TODO add initial setting here
        $this->_Log = SGN_Scribe::factory($channel);
        $this->_instance = $channel;
    }
    /**
     * function write
     * append specific string to final string
     * @param String $string
     */
    public function write($string)
    {
        if(gettype($string) === "string" && $string !== ''){
            $this->_loggingString .= $string;
            $this->_loggingString .= "\n";
        } else {
            $this->_Log->write("log string error : ");
            $this->_Log->write("type log error : " . gettype($string));
            $this->_Log->write("log content error : " . serialize($string));
        }
    }
    /**
     * Class Destructor
     *
     * perform some final action
     * Scribe logging
     */
    function __destruct()
    {
        if($this->_loggingString !== ''){
            $logString = rtrim($this->_loggingString);
            $this->_Log->write($logString);
        }
    }
}